<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/25
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms2.0/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms2.0/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms2.0/layui_ext/dtree/font/dtreefont.css">
</head>
<body class="childrenBody">
<!-- 搜索条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form" method="post" id="searchFrm">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">检查单号:</label>
            <div class="layui-input-inline" style="padding: 5px;width: 280px">
                <input type="text" name="checkid" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入检查单号" style="height: 30px;border-radius: 10px;width: 280px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">存在问题:</label>
            <div class="layui-input-inline" style="padding: 5px;width: 280px">
                <input type="text" name="problem" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入存在的问题" style="height: 30px;border-radius: 10px;width: 280px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">问题描述:</label>
            <div class="layui-input-inline" style="padding: 5px;width: 280px">
                <input type="text" name="checkdesc" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入问题描述" style="height: 30px;border-radius: 10px;width: 280px">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">出租单号:</label>
            <div class="layui-input-inline" style="padding: 5px;width: 280px">
                <input type="text" name="rentid" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入出租单号" style="height: 30px;border-radius: 10px;width: 280px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">开始时间:</label>
            <div class="layui-input-inline" style="padding: 5px;width: 280px">
                <input type="text" name="logintime1" id="logintime1" readonly="readonly"
                       class="layui-input layui-input-inline"
                       placeholder="请输入开始检查时间" style="height: 30px;border-radius: 10px;width: 280px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结束时间:</label>
            <div class="layui-input-inline" style="padding: 5px;width: 280px">
                <input type="text" name="logintime2" id="logintime2" readonly="readonly"
                       class="layui-input layui-input-inline"
                       placeholder="请输入结束检查时间" style="height: 30px;border-radius: 10px;width: 280px">
            </div>
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center">
        <div class="layui-input-black" >
            <button type="button"
                    class="layui-btn layui-btn-normal layui-icon layui-icon-search layui-btn-radius layui-btn-sm"
                    lay-submit  lay-filter="doSearch" style="margin-top: 4px">查询
            </button>
            <button type="reset"
                    class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm"
                    style="margin-top: 4px">重置
            </button>
        </div>
    </div>

</form>

<!-- 数据表格开始 -->
<table class="layui-hide" id="checkTable" lay-filter="checkTable"></table>
<script id="checkToolBar" type="text/html">
    <button type="button" class="layui-btn layui-btn-danger layui-btn-sm layui-btn-radius" lay-event="deleteBatch">批量删除</button>
</script>


<script id="checkBar" type="text/html">
    <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del">删除</a>
</script>


<!-- 添加和修改的弹出层-->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv">
    <form class="layui-form" lay-filter="dataFrm" id="dataFrm">
        <div class="layui-form-item">
            <label class="layui-form-label">检查单号:</label>
            <div class="layui-input-block">
                <input type="text" name="checkid" lay-verify="required" readonly="readonly" placeholder="请输入检查单号"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">出租单号:</label>
            <div class="layui-input-block">
                <input type="text" name="rentid" lay-verify="required" readonly="readonly" placeholder="请输入出租单号"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">检查时间:</label>
                <div class="layui-input-inline">
                    <input type="text" name="checkdate1" id="checkdate1" lay-verify="required" placeholder="请输入起租时间" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">存在问题:</label>
                <div class="layui-input-inline">
                    <input type="text" name="problem" lay-verify="required" id="problem" placeholder="请输入存在的问题" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">问题描述:</label>
                <div class="layui-input-inline">
                    <input type="text" name="checkdesc" lay-verify="required" placeholder="请输入问题描述"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">赔付金额:</label>
                <div class="layui-input-inline">
                    <input type="text" name="paymoney" lay-verify="required"  placeholder="请输入车牌号" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">操作员:</label>
                <div class="layui-input-inline">
                    <input type="text" name="openname" id="openname" lay-verify="required" placeholder="请输入操作员" readonly="readonly" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;padding-right: 120px">
                <button type="button"
                        class="layui-btn layui-btn-normal layui-btn-md layui-icon layui-icon-release layui-btn-radius"
                        lay-filter="doSubmit" lay-submit="">提交
                </button>
                <button type="reset"
                        class="layui-btn layui-btn-warm layui-btn-md layui-icon layui-icon-refresh layui-btn-radius">重置
                </button>
            </div>
        </div>
    </form>
</div>
<script src="${pageContext.request.contextPath}/static/layuicms2.0/layui/layui.js"></script>
    <script>
        var roleTree;
        var checkTable;
        var miniIndex;
        var url;
        var demoTree;
        layui.extend({
            dtree: '${pageContext.request.contextPath}/static/layuicms2.0/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
        }).use(['table','form','layer','jquery','dtree','upload','laydate'], function(){
            var table = layui.table
            var form = layui.form
            var layer = layui.layer
            var $ = layui.jquery
            var dtree = layui.dtree
            var upload=layui.upload
            var laydate = layui.laydate

            laydate.render({
                elem: '#logintime1' //指定元素
                ,type :"datetime"
            });

            laydate.render({
                elem: '#logintime2' //指定元素
                ,type :"datetime"
            });


            // 初始table
            checkTable = table.render({
                elem:"#checkTable"
                ,url:"/car/check/checkAll"
                ,page: {limit:5 ,limits:[5,10,15]} //开启分页
                ,cellMinWidth:80
                ,toolbar: '#checkToolBar' //开启头部工具栏，并为其绑定左侧模板
                ,cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'}
                    ,{field: 'checkid', title: '检查单号',  fixed: 'center'}
                    ,{field: 'rentid', title: '出租单号',   fixed: 'center'}
                    ,{field: 'problem', title: '存在问题',  fixed: 'center'}
                    ,{field: 'checkdesc', title: '问题描述',   fixed: 'center'}
                    ,{field: 'paymoney', title: '赔付金额',  fixed: 'center'}
                    ,{field: 'openname', title: '操作员',   fixed: 'center'}
                    ,{field: 'checkdate', title: '检查时间',   fixed: 'center'}
                    ,{field: 'createtime', title: '录入时间',   fixed: 'center'}
                    ,{fixed: 'right', title:'操作', toolbar: '#checkBar', width:280}
                ]]

            })

            // form表单提交  -- 查询功能
            form.on("submit(doSearch)",function(data) {
                checkTable.reload({
                    url:"/car/check/checkAll"
                    ,where :data.field
                    ,page:{
                        curr:1
                    }

                })
                return false;
            })

            // 头部工具栏添加事件
            table.on('toolbar(checkTable)',function(obj) {
               if(obj.event == "deleteBatch"){
                var checkStatus = table.checkStatus(obj.config.id)//获取选中的条数
                    if(checkStatus.data.length==0){//选择的条数=0就提示
                        layer.msg("您至少选择一条进行删除")
                    }else{
                    var ids=""
                    for(var i=0;i<checkStatus.data.length;i++){
                          ids+=checkStatus.data[i].checkid+","
                    }
                    $.post("/car/check/deleteAll",{"ids":ids},function (r) {//传ids到contorlle层进行批量删除
                        layer.msg(r.msg)
                        checkTable.reload()
                    })
                    }
                }
            })




            form.on('submit(doSubmit)', function (data) {
                $.post(url, data.field, function (r) {
                    if (r.code == 0) {
                        layer.close(miniIndex)
                        checkTable.reload({
                            page: {
                                curr: 1
                            }
                        })
                        layer.msg(r.msg, {icon: 1})
                    } else {
                        layer.msg(r.msg, {icon: 2})
                    }
                })
                return false;
            })




            //监听行工具事件
            table.on('tool(checkTable)', function(obj){
                var data = obj.data
                if(obj.event == "edit"){ // 编辑
                    carUpdate(data)
                }else  if(obj.event == "del"){ // 删除
                    del(data)
                }
            })


            function carUpdate(data) {
                miniIndex = layer.open({
                    type: 1
                    , title: "修改菜单"
                    , content: $("#saveOrUpdateDiv")
                    , area: ['750px', '450px']
                    , success: function (layero, index) {
                        form.val("dataFrm", data)
                        $("#checkdate1").val(data.checkdate)
                        url="/car/check/update"
                    }

                })
            }

            function del(data){
                layer.confirm("您确定要删除该记录吗",function (ind) {
                    $.post("/car/check/delete",{"checkid":data.checkid},function (r) {
                                layer.msg(r.msg)
                        checkTable.reload()
                    })
                    layer.close(ind)
                })
            }


        });


    </script>
</body>
</html>
